class Solution {
public:
    int canJump(vector<int>& nums) {
        int left = 0, right = 0, maxPos = 0, ret = 0, n = nums.size();
        // 这一次起跳的左端点，右端点，下一次起跳的右端点
        while(left <= right)
        {
            if(maxPos >= n - 1)
                return true;
            for(int i = left; i <= right; ++i)
            {
                maxPos = max(maxPos, i + nums[i]);
            }
            left = right + 1; // 更新起跳左右端点并++ret
            right = maxPos;
            ++ret;
        }
        return false;
    }
};